export default {
  addCart (state, goodsinfo) {
    var flag = false
    state.cart.some(item => {
      if (item.id == goodsinfo.id) {
        item.count += parseInt(goodsinfo.count)
        flag = true
        return true
      }
    })
    if (!flag) {
      state.cart.push(goodsinfo)
    }
    localStorage.setItem('cart', JSON.stringify(state.cart))
  },
  updateCart (state, goodsinfo) {
    state.cart.some(item => {
      if (item.id == goodsinfo.id) {
        item.count = parseInt(goodsinfo.count)
        return true
      }
    })
    localStorage.setItem('cart', JSON.stringify(state.cart))
  },
  removeCart (state, id) {
    state.cart.some((item, i) => {
      if (item.id == id) {
        state.cart.splice(i, 1)
        return true
      }
    })
    localStorage.setItem('cart', JSON.stringify(state.cart))
  },
  updateGoodsChanged (state, info) {
    state.cart.some(item => {
      if (item.id == info.id) {
        item.selected = info.selected
        return true
      }
    })
    localStorage.setItem('cart', JSON.stringify(state.cart))
  }
}
